<?php

namespace app\common\model;

use think\Model;
use think\Db;

class LinkModel extends Model
{
  protected $table = 'basic_link';
  protected $pageSize = 15;


  public function getAllLink(){
    $where = [
      'status' => 1,
    ];
    $list = Db::table($this->table)->where($where)->order("sort")->select();

    return [
      'list' => $list
    ];
  }

  public function getList($params){
    $curPage = isset($params['page'])&&$params['page']>=1  ? $params['page']: 1;
    $where['status'] = ['neq', 111];

    $totalRow = self::where($where)->count();
    $data = self::where($where)->page($curPage, $this->pageSize)->select();
    $data = empty($data) ? [] : collection($data)->toArray();

    return [
        'pageSize' => $this->pageSize,
        'totalRow' => $totalRow,
        'curPage' => $curPage,
        'data' => $data
    ];
  }

  public function findOne($id){
  	return self::find($id);
  }

  //删除
  public function deleteall($id)
  {
    if (!is_array($id)) {
      $id = [$id];
    }

    return self::where("id", "in", $id)->update([
      'status' => 111,
      'update_time' => time()
    ]);
  }


}